package com.aiyige.page.my.order.adapter.refund;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.aiyige.R;
import com.aiyige.utils.GlideUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/10/17.
 */
public class RefundPicListAdapter extends BaseQuickAdapter<RefundImageEntity, RefundPicListAdapter.ViewHolder> {

    public boolean isDetail() {
        return isDetail;
    }

    public void setDetail(boolean detail) {
        isDetail = detail;
    }

    private boolean isDetail = false;

    public RefundPicListAdapter() {
        super(R.layout.item_add_pic, new LinkedList<RefundImageEntity>());
    }

    @Override
    protected void convert(ViewHolder helper, RefundImageEntity item) {
        helper.bindData(item);
    }

    public class ViewHolder extends BaseViewHolder {

        @BindView(R.id.coverIv)
        ImageView coverIv;
        @BindView(R.id.deleteIv)
        ImageView deleteIv;
        @BindView(R.id.addLayout)
        LinearLayout addLayout;
        RefundImageEntity record;


        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(final RefundImageEntity entity) {
            record = entity;
            switch (record.getType()) {
                case RefundImageEntity.TYPE_ADD:
                    coverIv.setVisibility(View.INVISIBLE);
                    deleteIv.setVisibility(View.INVISIBLE);
                    addLayout.setVisibility(View.VISIBLE);
                    break;
                case RefundImageEntity.TYPE_NORMAL:
                    coverIv.setVisibility(View.VISIBLE);
                    deleteIv.setVisibility(isDetail()?View.INVISIBLE:View.VISIBLE);
                    addLayout.setVisibility(View.INVISIBLE);
                    GlideUtil.with(itemView.getContext())
                            .loadCover(entity.getPath())
                            .into(coverIv);
                    break;
            }
        }
    }

}
